package Q1446;

import java.util.*;

/**
 * 连续字符
 */
public class Test {
    public static void main(String[] args) {
        System.out.println(new Solution().maxPower2("leetcode"));
        System.out.println(new Solution().maxPower2("triplepillooooow"));
        System.out.println(new Solution().maxPower2("tourist"));
        System.out.println(new Solution().maxPower2("ccbccbb"));
        System.out.println(new Solution().maxPower2("ccbccbb"));
    }
}


class Solution {
    public int maxPower(String s) {
        if (s.length() == 0) {
            return 0;
        }
        if (s.length() == 1) {
            return 1;
        }
        int len = s.length();
        int count = 1;
        int res = 1;
        for (int i = 1; i < len; i++) {
            if(s.charAt(i) == s.charAt(i-1)){
                count++;
                res = Math.max(res,count);
            }else{
                count = 1;
            }
        }
        return res;
    }

    /**
     * 双指针/滑动窗口
     * @param s
     * @return
     */
    public int maxPower2(String s) {
        if (s.length() == 0) {
            return 0;
        }
        if (s.length() == 1) {
            return 1;
        }
        int left = 0;
        int right = 1;
        int res = 1;
        for (int i = 1; i < s.length(); i++) {
            if(s.charAt(i) == s.charAt(i-1)){
                right = i;
                res = Math.max(res,(right-left)+1);
            }else {
                left = i;
                right = left+1;
            }
        }
        return res;
    }

}
